package com.angis.fx.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class WGTypeDBHelper extends ObjectDBHelper {
	
	public static final String PK_WID = "wid";
	public static final String COLUMN_CONDITIONTYPE = "conditiontype";
	public static final String COLUMN_WGTYPE = "wgtype";
	public static final String COLUMN_CREATIONTIME = "creationtime";
	public static final String TABLE_WGTYPE = "wgtype";

	public WGTypeDBHelper(Context context) {
		super(context);
	}
	
	public long insertWGType(ContentValues pValues) {
		return insert(TABLE_WGTYPE, pValues);
	}
	
	public Cursor getAllWGTypeUseDistinct() {
		if (writeDB == null)
			writeDB = dbHelper.getReadableDatabase();
		return writeDB.queryWithFactory(null, true, TABLE_WGTYPE, new String[]{PK_WID,
				COLUMN_CONDITIONTYPE, COLUMN_WGTYPE, COLUMN_CREATIONTIME}, null, null, "conditiontype", null, null, null);
	}
	
	public Cursor getWGTypeByConditionType(String pConditionType) {
		String[] lParams = new String[]{pConditionType};
		if (writeDB == null)
			writeDB = dbHelper.getReadableDatabase();
		return writeDB.query(TABLE_WGTYPE, new String[]{PK_WID,
				COLUMN_CONDITIONTYPE, COLUMN_WGTYPE, COLUMN_CREATIONTIME}, "conditiontype=?", lParams, null, null, null);
	}
	
	public boolean delAll() {
		if(null == writeDB) {
			writeDB = dbHelper.getWritableDatabase();
		}
		return writeDB.delete(TABLE_WGTYPE, null, null) > 0;
	}

}
